import { createRouter, createWebHistory } from 'vue-router'

// 导入路由组件
import Layout from '@/views/Layout/index.vue'
import Login from '@/views/Login/index.vue'
import Home from '@/views/Home/index.vue'
import RoomList from '@/views/RoomList/index.vue'
import RoomHot from '@/views/RoomHot/index.vue'
import RoomDetail from '@/views/RoomDetail/index.vue'
import UserCenter from '@/views/UserCenter/index.vue'
import Apartment from '@/views/Apartment/index.vue'
import Villa from '@/views/Villa/index.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      component: Layout,
      children: [
        { path: '', component: Home }, //Home页
        { path: '/list', component: RoomList }, //房源列表页
        { path: '/hot', component: RoomHot }, //热门房源页
        { path: '/apartment', component: Apartment }, //品牌公寓页
        { path: '/villa', component: Villa }, //精选别墅页
        { path: '/detail/:id', component: RoomDetail }, //房源详情页
        { path: '/user', component: UserCenter } //个人中心页
      ]
    }, //布局架子
    {
      path: '/login',
      component: Login
    } //登录页
  ],

  // 路由行为配置项，路由跳转后回到页面顶部位置
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { top: 0 }
    }
  }
})

export default router
